﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Web.Utils
{
    public class StringHelper
    {
        /// <summary>
        /// 得到指定长度的字符串，不够长的后面补空格
        /// </summary>
        /// <param name="str"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetLengthString(string str, int length)
        {
            if (str.Length < length)
            {
                str = str.PadRight(length, ' ');
            }
            return str;
        }

        public static string GetLengthStringWithChar(string str, int length, char c)
        {
            if (str.Length < length)
            {
                str = str.PadRight(length, c);
            }
            return str;
        }

        /// <summary>
        /// 将字符串长度增加至16，不够长的后面补空格
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Get16String(string str)
        {
            return GetLengthString(str, 16);
        }

        /// <summary>
        /// 将字符串长度增加至32，不够长的后面补空格
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Get32String(string str)
        {
            return GetLengthString(str, 32);
        }
    }
}